package com.mresources.common.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.SneakyThrows;

public class JsonUtil {
    private static final ObjectMapper mapper = new ObjectMapper();

    @SneakyThrows
    public static <T> T stringToObject(String json, Class<T> clz) {
        if (json == null || "null".equals(json) || "".equals(json)) {
            return null;
        }
        return mapper.readValue(json, clz);
    }

    @SneakyThrows
    public static String objectToString(Object o) {
        return mapper.writeValueAsString(o);
    }
}
